import Cookies from "js-cookie";

const TokenKey = "Admin-Token";

export function getToken() {
  return Cookies.get(TokenKey);
}

export function setToken(token) {
  return Cookies.set(TokenKey, token);
}

export function removeToken() {
  return Cookies.remove(TokenKey);
}

/**
 * 判断是否过期
 */
export const isExpired = date => {
  if (!new Date(date).getTime()) {
    return false;
  }
  let expiredDate = new Date(date).getTime();
  let nowDate = new Date().getTime();
  if (nowDate > expiredDate) {
    //过期返回true
    return true;
  } else {
    return false;
  }
};
